#ifndef SBOTMAINWINDOW_H
#define SBOTMAINWINDOW_H

#include "MySbotCfg.h"
#include "SbotPluginManager.h"

#include <QQmlContext>
#include <QQuickItem.h>
#include <QQuickWindow.h>
#include <dwmapi.h>
#include <qdebug.h>
#include <windows.h>
#include <windowsx.h>

class SbotMainWindow : public QQuickWindow
{
    Q_OBJECT
    QML_ELEMENT

  public:
    explicit SbotMainWindow(QWindow* parent = nullptr);
    ~SbotMainWindow() override = default;

  private:
    int              curPluginViewId  = -1;       // 当前插件id
    QQuickItem*      curPluginQmlItem = nullptr;  // 当前插件qml对象
    SbotPluginManger pluginManger;                // 插件管理器

  private:
    void SetWindowsStyle();
    int  AdjustResizeWindow(HWND hwnd, const QPoint& mousePos);
    void AdjustWindowContentMarginsWhenMaximized(bool isMaximized);
    int  LoadPlugin(int pluginIndex);  // 加载插件
    void RefreshPluginListView();      // 刷新插件列表视图

  protected:
    bool nativeEvent(const QByteArray& eventType, void* message, qintptr* result) override;
    bool event(QEvent* event) override;
    void mouseDoubleClickEvent(QMouseEvent* event) override;
    void showEvent(QShowEvent* event) override;

  public slots:
    void windowsExit();
    void onPluginListLoaded();
    void onPluginDetailLoaded();
    void swPluginView(int pluginId);  // 切换插件视图槽
};

#endif  // SBOTMAINWINDOW_H
